package ru.spbau.database.group3.parser;

import ru.spbau.database.group3.queryEvaluator.ErrorInstruction;
import ru.spbau.database.group3.queryEvaluator.Instruction;

import java.io.IOException;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: stas
 * Date: 1/29/13
 * Time: 1:19 PM
 */
public class Parser {
    public Parser() {
        commands = new ArrayList<Command>();
        commands.add(new SelectCmd());
        commands.add(new CreateTableCmd());
        commands.add(new InsertCmd());
        commands.add(new CreateIndexCmd());
        commands.add(new CreateUniqueIndexCmd());
        commands.add(new UpdateTableCmd());
        commands.add(new DeleteCmd());
    }

    public Instruction parse(String cmd) throws IOException {
        for(Command c : commands) {
            if(c.isApplicable(cmd)) {
                return c.process(cmd);
            }
        }
        return new ErrorInstruction("Unsupported request " + cmd);
    }

    private ArrayList<Command> commands;

}
